local chimai = fk.CreateSkill{
  name = "hanqing__chimai",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["hanqing__chimai"] = "炽脉",
  [":hanqing__chimai"] = "锁定技，游戏开始时，将牌堆转为“火焰山”形态：牌堆顶牌始终明置，且于你受到伤害后<a href=':hanqing__burst'>“爆发”</a>。",

  ["@$hanqing__burst"] = "火焰山",
}

local U = require "packages/hanqing/util"

chimai:addEffect(fk.GameStart, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(chimai.name)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local info = room:getBanner("hanqing__burst") or {}
    info.players = info.players or {}
    table.insertIfNeed(info.players, player.id)
    room:setBanner("hanqing__burst", info)
  end,
})

chimai:addEffect(fk.Damaged, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and not player.dead and
      player.room:getBanner("hanqing__burst") and
      table.contains(player.room:getBanner("hanqing__burst").players, player.id)
  end,
  on_use = function (self, event, target, player, data)
    U.burst(player)
  end,
})

chimai:addEffect("visibility", {
  card_visible = function (self, player, card)
    if Fk:currentRoom():getBanner("hanqing__burst") and
      Fk:currentRoom().draw_pile[1] == card.id then
      return true
    end
  end,
})

local spec = {
  priority = 0,
  can_refresh = function (self, event, target, player, data)
    return player.seat == 1 and player.room:getBanner("hanqing__burst")
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setBanner("@$hanqing__burst", room:getNCards(1))
  end
}

chimai:addEffect(fk.AfterCardsMove, spec)
chimai:addEffect(fk.AfterDrawPileShuffle, spec)
chimai:addEffect(fk.AfterSkillEffect, spec)

return chimai
